'use strict'

/**
 * @param {string} s
 * @return {number}
 */
var lengthOfLongestSubstring = function(s) {
    const set = new Set();
    let maxLength = 0;
    let fi = 0;
    for(let i = 0; i < s.length; i++) {
        const c = s[i];
        while (set.has(c)) {
            const nc = s[fi];
            fi++;
            set.delete(nc);
        }
        set.add(c);
        const length = i - fi + 1;
        if (length > maxLength) {
            maxLength = length;
        }
    }
    return maxLength;
};
